MACRO(QT_AUTO_WRAP outfiles)
    FOREACH(fileName ${ARGN})
        IF(fileName MATCHES "\\.h$")
            FILE(STRINGS ${fileName} lines REGEX Q_OBJECT)
            IF(lines)
                SET(moc_headers ${moc_headers} ${fileName})
                #MESSAGE(STATUS "moc: ${fileName}")
            ENDIF()
        ENDIF()
        IF(fileName MATCHES "\\.ui$")
            SET(ui_files ${ui_files} ${fileName})
            #MESSAGE(STATUS "uic: ${fileName}")
        ENDIF()
        IF(fileName MATCHES "\\.qrc$")
            SET(qrc_files ${qrc_files} ${fileName})
            #MESSAGE(STATUS "qrc: ${fileName}")
        ENDIF()
    ENDFOREACH()
	IF(USE_QT5)
        QT5_WRAP_CPP(${outfiles} ${moc_headers})
        QT5_WRAP_UI(${outfiles} ${ui_files})
        QT5_ADD_RESOURCES(${outfiles} ${qrc_files})
	ELSE()
		QT4_WRAP_CPP(${outfiles} ${moc_headers})
        QT4_WRAP_UI(${outfiles} ${ui_files})
        QT4_ADD_RESOURCES(${outfiles} ${qrc_files})
	ENDIF()
ENDMACRO()

MACRO(SOURCE_GROUP_BY_PATH)
    FOREACH(filename ${ARGV})
        GET_FILENAME_COMPONENT(path "${filename}" REALPATH)
        FILE(RELATIVE_PATH path ${PROJECT_SOURCE_DIR} ${path})
        GET_FILENAME_COMPONENT(path "${path}" PATH)
        string(REPLACE "/" "\\" path "${path}")
        IF(${filename} MATCHES "ui_|cxx$")
            SOURCE_GROUP("generated" FILES ${filename})
        ELSEIF(${filename} MATCHES "h$|hpp$|cpp$|c$|cu$|ui$|qrc$")
            SOURCE_GROUP("${path}" FILES ${filename})
        ENDIF()
    ENDFOREACH()
ENDMACRO(SOURCE_GROUP_BY_PATH)
